<?php
/**
 * Created by PhpStorm.
 * User: zhangligang
 * Date: 17/4/24
 * Time: 上午12:01
 */

namespace App\Http\Service;


use App\Http\Repository\ArticleRepository;

class ArticleService extends Service
{

    /**
     * @param ArticleRepository $repository
     */
    public function __construct(ArticleRepository $repository)
    {
        parent::__construct($repository);

    }

    /**
     * @param string $title
     * @param int $page
     * @param int $pageSize
     * @return mixed
     */
    public function searchByTitle($title, $page, $pageSize)
    {
        $where = [
            'key' => 'title',
            'operator' => 'LIKE',
            'value' => "{$title}%"
        ];

        $offset = ($page - 1) * $pageSize;

        return $this->repository->getProductList($where, $offset, $pageSize);
    }

    /**
     * @param int $id
     * @return mixed
     */
    public function searchById($id)
    {
        return $this->repository->getProductById($id);
    }

}